package juc.thread.threadPool;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

/*
线程池中的异常处理
手动try cache
通过调用callable任务 通过发t.get()可以拿到正确结果|异常信息
* */
public class Test9 {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ExecutorService executorService = Executors.newFixedThreadPool(1);
        executorService.submit(()->{
            try {
                System.out.println("task1");
                int i=1/0;
            } catch (Exception e) {
                System.out.println("记录日志...");
            }
        });
        executorService.submit(()->{
            System.out.println("task2");
//            int i=1/0;
        });
        Future<Boolean> task3 = executorService.submit(() -> {
            System.out.println("task3");
            int i=1/0;
            return true;
        });
        System.out.println(task3.get());
    }
}
